<template>
  <div class="order-detail" v-if="orderInfo">
    <Scroll class="order-detail-scroll">
      <div class="content">
        <div class="inner">
          <div class="content-top" v-if="orderInfo.delivery_type === 2 && orderInfo.status === 1">
            <p class="status">未发货</p>
            <p class="tip">正在备货，请耐心等待~</p>
          </div>
          <div class="content-top" v-if="orderInfo.delivery_type === 1 && orderInfo.status === 1">
            <p class="status">未领取</p>
            <p class="tip">交易完成，祝您生活愉快～</p>
          </div>
          <div class="content-top" v-if="orderInfo.delivery_type === 2 && orderInfo.status === 2 || orderInfo.delivery_type === 1 && orderInfo.status === 2">
            <p class="status">兑换成功</p>
            <p class="tip">产品在路上了，请耐心等待～</p>
          </div>
          <div class="deliver-msg">
            <div class="top">
              <div class="left">
                <i></i>
                <span>选择配送方式</span>
              </div>
              <div class="right">{{orderInfo.delivery_type === 1 ? '到店自提' : '快递配送'}}</div>
            </div>
            <div class="bottom">
              <div class="left">
                <i class="icon_adr"></i>
              </div>
              <div class="center" v-if="orderInfo.delivery_type === 2">
                <p class="user-info">
                  <span class="name" style="margin-right: 0.15rem">{{orderInfo.receiver_name}}</span>
                  <span class="tel">{{orderInfo.receiver_phone}}</span>
                </p>
                <p class="adr">{{orderInfo.area}} {{orderInfo.receiver_address}}</p>
              </div>
              <div class="center" v-if="orderInfo.delivery_type === 1">
                <p class="user-info">
                  <span class="name">营业时间：</span>
                  <span class="tel">{{orderInfo.shop_address.split(' ')[1]}}</span>
                </p>
                <p class="adr">{{orderInfo.shop_address.split(' ')[0]}}</p>
              </div>
              <!-- <div class="right">
                <i class="icon_back"></i>
              </div> -->
            </div>
          </div>
          <panel-order-detail
            @checkLogistics="handleCheckLogistics(orderInfo)"
            :activeIndex="orderInfo.delivery_type === 1 ? 0 : 1"
            :goodsInfo="orderInfo"
          />
          <div class="order-info">
            <div class="info-title">订单详细</div>
            <div class="info-msg">
              <div class="order-no">
                <span class="no">订单编号：{{orderInfo.number}}</span>
                <span
                  class="copy"
                  v-clipboard:copy="orderInfo.number"
                  v-clipboard:success="onCopy"
                  v-clipboard:error="onError"
                >复制</span>
              </div>
              <div class="create-time">创建时间：{{orderInfo.created_at}}</div>
              <div class="confirm-time">确认时间：{{orderInfo.updated_at}}</div>
            </div>
          </div>
        </div>
      </div>
    </Scroll>
    <div class="contact">
      <i></i>
      <span>
        <a href="tel: 13918958807">联系客服</a>
      </span>
    </div>
    <transition name="slide">
      <router-view></router-view>
    </transition>
  </div>
</template>
<script>
import Scroll from '@/components/scroll/scroll'
import PanelOrderDetail from './panel-order-detail'
import { getOrderGoodsDetail } from '@/api/my'
const ERR_OK = 200
export default {
  components: {
    Scroll,
    PanelOrderDetail
  },
  data () {
    return {
      orderInfo: null
    }
  },
  created () {
    if (this.$route.query.orderId && this.$route.query.information_id) {
      this._getOrderGoodsDetail(this.$route.query.orderId, this.$route.query.information_id)
    }
    if (this.$route.query.orderId && !this.$route.query.information_id) {
      this._getOrderGoodsDetail(this.$route.query.orderId)
    }
  },
  beforeRouteLeave (to, from, next) {
    // ...
    this.$emit('success')
    next()
  },
  methods: {
    onCopy (e) {
      this.$toast('复制成功')
      this.show = false
    },
    onError (e) {
      this.$toast('复制失败')
    },
    handleCheckLogistics (orderInfo) {
      this.$router.push({
        path: '/my/exchange-center/order-detail/check-logistics',
        query: { orderInfo: orderInfo }
      })
    },
    _getOrderGoodsDetail (id, informationId) {
      getOrderGoodsDetail(id, informationId).then(res => {
        if (res.code === ERR_OK) {
          console.log(res)
          this.orderInfo = res.data
        }
      })
    }
  }
}
</script>
<style lang="scss" scoped>
@import "@/styles/mixin.scss";
@include slideEnter();
.order-detail {
  position: fixed;
  left: 0;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 12;
  touch-action: none;
  background: #fafafa;
  .inner {
    width: 100%;
    height: 100%;
    padding-bottom: 1rem;
  }
  .order-detail-scroll {
    width: 100%;
    height: 100%;
  }
  .content {
    width: 100%;
    padding: 0.4rem 0.36rem;
    box-sizing: border-box;
    .content-top {
      width: 100%;
      background: rgba(0, 4, 0, 1);
      display: flex;
      flex-direction: column;
      padding: 0.56rem 0.36rem;
      box-sizing: border-box;
      .status {
        font-size: 0.28rem;
        font-family: PingFang SC;
        font-weight: 500;
        color: rgba(255, 255, 255, 1);
        line-height: 0.32rem;
      }
      .tip {
        font-size: 0.22rem;
        font-family: PingFang SC;
        font-weight: 400;
        color: rgba(255, 255, 255, 0.68);
        line-height: 0.32rem;
        margin-top: 0.2rem;
      }
    }
    .deliver-msg {
      width: 6.78rem;
      background: rgba(255, 255, 255, 1);
      font-size: 0;
      margin-top: 0.42rem;
      .top {
        width: 100%;
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 0.3rem 0.34rem;
        box-sizing: border-box;
        border-bottom: 1px solid #eeeeee;
        .left {
          height: 100%;
          display: flex;
          align-items: center;
          i {
            display: inline-block;
            width: 0.41rem;
            height: 0.33rem;
            background: url("../../../assets/images/cc.png") no-repeat;
            background-size: cover;
            margin-right: 0.3rem;
          }
          span {
            font-size: 0.26rem;
            font-family: PingFang SC;
            font-weight: 400;
            color: rgba(0, 4, 0, 1);
          }
        }
        .right {
          font-size: 0.24rem;
          font-family: PingFang SC;
          font-weight: 400;
          color: rgba(0, 4, 0, 1);
        }
      }
      .bottom {
        width: 100%;
        padding: 0.39rem 0.34rem;
        box-sizing: border-box;
        display: flex;
        justify-content: space-between;
        align-items: center;
        .left {
          i {
            display: inline-block;
            width: 0.36rem;
            height: 0.36rem;
            background: url("../../../assets/images/dz.png") no-repeat;
            background-size: cover;
          }
        }
        .center {
          .user-info {
            display: flex;
            .name {
              font-size: 0.28rem;
              font-family: PingFang SC;
              font-weight: 500;
              color: rgba(0, 4, 0, 1);
              line-height: 0.32rem;
              // margin-right: 0.18rem;
            }
            .tel {
              font-size: 0.24rem;
              font-family: PingFang SC;
              font-weight: 400;
              color: rgba(123, 123, 123, 1);
              line-height: 0.32rem;
            }
          }
          .adr {
            width: 5rem;
            font-size: 0.24rem;
            font-family: PingFang SC;
            font-weight: 400;
            color: rgba(51, 51, 51, 1);
            margin-top: 0.26rem;
            line-height: 0.32rem;
            // @include ellipsis();
          }
        }
        .right {
          height: 100%;
          padding: 0.2rem 0.1rem;
        }
      }
    }

    .order-info {
      width: 100%;
      background: rgba(255, 255, 255, 1);
      padding: 0.5rem 0.3rem;
      margin-top: 0.42rem;
      box-sizing: border-box;
      .info-title {
        font-size: 0.28rem;
        font-family: PingFang SC;
        font-weight: 500;
        color: rgba(0, 4, 0, 1);
        line-height: 0.36rem;
        font-weight: bold;
      }
      .info-msg {
        margin-top: 0.54rem;
        .order-no {
          display: flex;
          justify-content: space-between;
          align-items: center;
          .no {
            font-size: 0.26rem;
            font-family: PingFang SC;
            font-weight: 400;
            color: rgba(102, 102, 102, 1);
          }
          .copy {
            font-size: 0.28rem;
            font-family: PingFang SC;
            font-weight: 400;
            color: rgba(0, 4, 0, 1);
            line-height: 0.36rem;
          }
        }
        .create-time,
        .confirm-time {
          font-size: 0.26rem;
          font-family: PingFang SC;
          font-weight: 400;
          color: rgba(102, 102, 102, 1);
          margin-top: 0.36rem;
        }
      }
    }
  }
  .contact {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 1rem;
    background: #fff;
    position: fixed;
    left: 0;
    bottom: 0;
    i {
      display: inline-block;
      width: 0.4rem;
      height: 0.38rem;
      background: url("../../../assets/images/kf.png") no-repeat;
      background-size: cover;
      margin-right: 0.35rem;
    }
    span {
      font-size: 0;
      a {
        font-size: 0.28rem;
        font-family: PingFang SC;
        font-weight: 400;
        color: rgba(68, 68, 68, 1) !important;
      }
    }
  }
}
</style>
